using System;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.Provider
{
    public class ProviderCompanyServicesDB
    {
        public ProviderCompanyServicesDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public ProviderCompanyServices GetProviderServices(Int64 PSID, Int64 ProviderCompanyId)
        {
            MyDatabase _Db = new MyDatabase();
            string _spName = "sprocProviderCompanyServicesSelectSingleItem";
            ProviderCompanyServices _result = null;
            DataTable _dt;
            SortedList _sPara = new SortedList();
            _sPara.Add("@PSID", PSID);
            _sPara.Add("@ProviderCompanyId", ProviderCompanyId);

            _dt = _Db.GetDataTableBySP(_spName, _sPara);

            if (_dt != null && _dt.Rows.Count > 0)
            {
                _result = new ProviderCompanyServices();
                _result = FillDataRecord(_dt, 0);
            }

            return _result;
        }

        public ProviderCompanyServicesList GetProviderCompanyServicesListGroupBy()
        {
            ProviderCompanyServicesList _pservicelist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocProviderCompanyServicesListGroupBy]";

            SortedList _spara = new SortedList();

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _pservicelist = new ProviderCompanyServicesList();
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        ProviderCompanyServices _pservices = new ProviderCompanyServices();
                        _pservices = FillDataRecordCompanyId(_dt, i);
                        _pservicelist.Add(_pservices);
                    }
                }
            }
            return _pservicelist;
        }

        public ProviderCompanyServicesList GetProviderCompanyListByProviderTypeId(Int32 ProviderTypeId)
        {
            ProviderCompanyServicesList _pservicelist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "[sprocProviderCompanyListByProviderTypeId]";

            SortedList _spara = new SortedList();

            _spara.Add("@ProviderTypeId", ProviderTypeId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _pservicelist = new ProviderCompanyServicesList();
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        ProviderCompanyServices _pservices = new ProviderCompanyServices();
                        _pservices = FillDataRecord(_dt, i);
                        _pservicelist.Add(_pservices);
                    }
                }
            }
            return _pservicelist;
        }

        public ProviderCompanyServicesList GetProviderServicesList(Int64 ProviderCompanyId)
        {
            ProviderCompanyServicesList _pservicelist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCompanyServicesSelectItemList";

            SortedList _spara = new SortedList();
            
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _pservicelist = new ProviderCompanyServicesList();
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        ProviderCompanyServices _pservices = new ProviderCompanyServices();
                        _pservices = FillDataRecord(_dt, i);
                        _pservicelist.Add(_pservices);
                    }
                }
            }
            return _pservicelist;
        }

        public Int64 Insert(ProviderCompanyServices pservices)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCompanyServicesInsertUpdateSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            //_sPara.Add("@PSID", pservices.PSID);
            _sPara.Add("@ProviderCompanyId", pservices.ProviderCompanyId);
            _sPara.Add("@ProviderTypeId", pservices.ProviderTypeId);
            _sPara.Add("@UpdateFlag", pservices.UpdateFlag);
            _sPara.Add("@Status", pservices.Status);
            _sPara.Add("@Info1", pservices.Info1);
            _sPara.Add("@Info2", pservices.Info2);
            _sPara.Add("@Info3", pservices.Info3);
            _sPara.Add("@Info4", pservices.Info4);
            _sPara.Add("@Info5", pservices.Info5);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Update(ProviderCompanyServices pservices)
        {
            return Insert(pservices) > 0;
        }

        public bool Delete()
        {
            return true;
        }

        private ProviderCompanyServices FillDataRecordCompanyId(DataTable myDataTable, int rowId)
        {
            ProviderCompanyServices myCompanyServices = new ProviderCompanyServices();
            myCompanyServices.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[rowId]["ProviderCompanyId"].ToString());
            return myCompanyServices;
        }

        private ProviderCompanyServices FillDataRecord(DataTable myDataTable, int rowId)
        {
            ProviderCompanyServices myCompanyServices = new ProviderCompanyServices();
            myCompanyServices.PSID = Convert.ToInt64(myDataTable.Rows[rowId]["PSID"].ToString());
            myCompanyServices.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[rowId]["ProviderCompanyId"].ToString());
            myCompanyServices.ProviderTypeId = Convert.ToInt32(myDataTable.Rows[rowId]["ProviderTypeId"].ToString());
            myCompanyServices.Status = Convert.ToBoolean(myDataTable.Rows[rowId]["Status"].ToString());

            return myCompanyServices;
        }
    }
}